import { type Data,type maxobj, type search,type searchSuggest,type searchResult,type TotalOptions,type Recommend} from '@/typings';  
import request from '../untils/request'
import axios from 'axios'
  

export const homerecommed = async ()=>{
    let {data} = await request.get<Array <Data>>("api/page")
    
    return data
}

export const LookMoreInfo= async (id:number)=>{
    let {data} = await axios.get<maxobj>(`https://apis.netstart.cn/xmsc/home/channel1_info?page_id=${id}`)
    
    return data
}

export const getTabInfo= async (pageId:number,blockId:number,id:number,size:number)=>{
    let url = `https://apis.netstart.cn/xmsc/home/channel1_tab?page_id=${pageId}&type=classification&block_id=${blockId}&id=${id}&page_size=${size}&page_index=1`
    
    let {data} = await axios.get<maxobj>(url)
    
    return data
}


export const homeIntell = async ()=>{
    let {data} = await request.get <maxobj>("api/zhineng")
    
    return data
}
export const getSearchList = async ()=>{
    let {data} = await request.get <search>("api/search")
    
    return data
}

export const getSearchSuggest = async (query:string)=>{
    let {data} = await axios.get <searchSuggest>(`https://apis.netstart.cn/xmsc/hisearch/suggestion_v3?query=${query}`)
    
    return data
}
export const getSearchResult = async (query:string,size:number)=>{

    let url = `https://apis.netstart.cn/xmsc/hisearch/query_v3?query=${query}&page_index=0&page_size=${size}&main_sort=0`
    console.log(url);
    
    let {data} = await axios.get <searchResult>(url)
    
    return data
}

export const getOptionsData = async (query:string,size:number,obj:TotalOptions,tag:number)=>{
    let url = `https://apis.netstart.cn/xmsc/hisearch/query_v3?query=${query}&page_index=1&page_size${size}&main_sort=0&activity_id&activity_type&class_parameters=${JSON.stringify(obj)}&filter_tag=${tag}`
    let {data}  = await axios.get <searchResult>(url)
    return data
}

export const recommend = async()=>{
    let {data} = await request.get<Recommend>("api/recommend")
    return data
}
export const kefu = async(ct:string)=>{
    let {data} = await axios.get('/my-proxy/api.php', {
        params: {
          key: 'free',
          appid: 0,
          msg: ct
        }
      })
    return data
}

